<template>
  <div class="messageAll">
    <van-cell
      v-for="item in messageAllData"
      :key="item.id"
      is-link
      to=""
      center
      :value="item.createTime"
      :label="'发布人：' + item.sourceName"
      @click="changeMessage(item.id)"
    >
      <template #icon>
        <van-icon :name="avatar" :dot="isShowDot" class="avatar" />
      </template>
      <template #title>
        <span class="custom-title">{{ item.title }}</span>
        <van-icon :name="backTop" v-show="item.top == 1 ? true : false" />
      </template>
    </van-cell>
  </div>
</template>

<script>
import { GetmessageAllData } from "@/request/api";
export default {
  data() {
    return {
      avatar: require("../assets/img/个人信息.png"),
      messageAllData: [],
      isShowDot: true,
      messageType: 0,
      backTop: require("../assets/img/置顶.png"),
    };
  },
  created() {
    // if (this.activeName == "messageAll") {
    //   this.messageType = 0;
    // } else if (this.activeName == "messageSystem") {
    //   this.messageType = 1;
    // } else {
    //   this.messageType = 2;
    // }
    GetmessageAllData({
      current: "1",
      size: "20",
      type: this.messageType,
    }).then((res) => {
      //   console.log(this.messageType);
      //   console.log(res);
      this.messageAllData = res.data.records;
      this.messageAllData.map((item) => {
        if (item.type == 1) {
          this.avatar = require("../assets/img/系统消息.png");
        } else {
          return;
        }
        if (item.isReader == 0) {
          this.isShowDot = false;
        }
      });
    });
  },
  methods: {
    changeMessage(id) {
      this.$router.push(`/message/details?id=` + id);
    },
  },
};
</script>
 
<style lang = "less" scoped>
.messageAll {
  margin-top: 10px;
}
.van-cell__left-icon {
  line-height: 46px;
  height: 46px;
}
.avatar {
  img {
    width: 50px;
    height: 46px;
  }
}
</style>